/**
 * 
 */
package com.imooc.security.core.social.gitee.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;

import com.imooc.security.core.properties.GiteeProperties;
import com.imooc.security.core.properties.QQProperties;
import com.imooc.security.core.properties.SecurityProperties;
import com.imooc.security.core.social.ImoocConnectView;
import com.imooc.security.core.social.gitee.connet.GiteeConnectionFactory;
import com.imooc.security.core.social.qq.connet.QQConnectionFactory;

/**
 * @author zhailiang
 *
 */
@Configuration
//上面是否有配置，有就底下配置才生效
@ConditionalOnProperty(prefix = "imooc.security.social.gitee", name = "app-id")
@Order(2)
public class GiteeAutoConfig extends SocialAutoConfigurerAdapter {

	@Autowired
	private SecurityProperties securityProperties;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter
	 * #createConnectionFactory()
	 */
	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		GiteeProperties giteeConfig = securityProperties.getSocial().getGitee();
		return new GiteeConnectionFactory(giteeConfig.getProviderId(), giteeConfig.getAppId(), giteeConfig.getAppSecret());
	}
	@Bean({"connect/giteeConnect", "connect/giteeConnected"})
	@ConditionalOnMissingBean(name = "giteeConnectedView")
	public View giteeConnectedView() {
		return new ImoocConnectView();
	}
}
